﻿#define Debug
using Spire.Pdf;
using Spire.Pdf.General.Find;

#if Debug
#endif

namespace PDFRun;

public class Paper
{
    readonly string _path;
    readonly string _fileName;
    readonly string? _fileDiert;
    readonly PdfDocument _document;

    public Paper(string path)
    {
        _path = path;
        _fileName = Path.GetFileNameWithoutExtension(_path);
        _fileDiert = Path.GetDirectoryName(_path);
        _document = new(_path);
        Praser();
    }

    private void Praser()
    {
#if Debug
        MiniDebug txtFins_debug = new("txtFinds", _fileName);
        MiniDebug page_debug = new("page", _fileName);
        MiniDebug info_debug = new("info", _fileName);
#endif
        foreach (PdfPageBase page in _document.Pages)
        {
            page_debug.Write(page.ExtractText());
            foreach (PdfTextFind txt in page.FindAllText().Finds)
            {
#if Debug
                txtFins_debug.Write($"[{txt.MatchText}] " +
                    $"Position: [{txt.Position}] " +
                    $"Size: [{txt.Size}]");
#endif
            }
        }

        txtFins_debug.Close();
        page_debug.Close();
        info_debug.Close();
        _document.SaveToFile($"{AppDomain.CurrentDomain.BaseDirectory}save_{_fileName}.html", FileFormat.HTML);
        _document.SaveToFile($"{AppDomain.CurrentDomain.BaseDirectory}save_{_fileName}.xlsx", FileFormat.XLSX);
        _document.SaveToFile($"{AppDomain.CurrentDomain.BaseDirectory}save_{_fileName}.pcl", FileFormat.PCL);
    }

    private void AddTitle(string title)
    {

    }

    private void AddAuthor(string authors)
    {

    }

    private void AddChapter(Chapter chapter)
    {

    }

    public void SaveTxt()
    {

    }

    public void SaveWithTranslate()
    {

    }
}
internal class Chapter
{

}
